package com.accp.controller;


import java.time.LocalDateTime;

import javax.security.auth.message.callback.PrivateKeyCallback.Request;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.accp.entity.TzSysUser;
import com.accp.entity.TzUser;
import com.accp.response.ResultResponse;
import com.accp.service.ITzSysUserService;
import com.accp.util.ResultVOUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * <p>
 * 系统用户 前端控制器
 * </p>
 *
 * @author 辉
 * @since 2019-12-26
 */
@RestController
@RequestMapping("/accp/tzSysUser")
public class TzSysUserController {

	@Autowired
	ITzSysUserService iTzSysUserService;
	
	@PostMapping("/loginUser")
	public ResultResponse loginUser(@RequestBody TzSysUser tzSysUser,HttpSession sess) {
		TzSysUser sysUser = iTzSysUserService.getOne(new QueryWrapper<TzSysUser>().eq("username", tzSysUser.getUsername())
				.eq("password", tzSysUser.getPassword()));
		if(sysUser!=null) {
			sess.setAttribute("thisUser", sysUser);
			return ResultVOUtil.success(sysUser);
		}else {
			return ResultVOUtil.success(null);
		}
	}
	
	@PostMapping("/sysUserAdd")
	public ResultResponse sysUserAdd(TzSysUser tzSysUser,HttpSession sess) {
		Long id = ((TzSysUser)sess.getAttribute("thisUser")).getUserId();
		tzSysUser.setCreateUserId(id);
		tzSysUser.setStatus(1);
		tzSysUser.setCreateTime(LocalDateTime.now());
		return ResultVOUtil.success(iTzSysUserService.save(tzSysUser));
	}
	
	@GetMapping("/getConditionUserDetail")
	public ResultResponse getConditionUserDetail(TzSysUser tzSysUser) {
		
		return ResultVOUtil.success(iTzSysUserService.list());
	}
	
}

